using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;

namespace SAE.Plugin
{
    public abstract class SPSAdminJob
    {
        public int TotalProgressMaximumStep;

        public int CurrentProgressMaximumStep;

        public delegate void ProgressChangedHandler(object sender, AdminJobEventArgs e);

        public event ProgressChangedHandler TotalProgressChanged;

        public event ProgressChangedHandler CurrentProgressChanged;

        public event EventHandler CurrentProgressResetted;

        protected abstract int OnRun(Object parameter);

        public int Run(Object parameter)
        {
            return OnRun(parameter); 
        }

        protected void ReportTotalProgress(int step, string progressMessage)
        {
            TotalProgressChanged(this, new AdminJobEventArgs(this.TotalProgressMaximumStep, step, progressMessage));
        }

        protected void ReportCurrentProgress(int step, string progressMessage)
        {
            CurrentProgressChanged(this, new AdminJobEventArgs(this.CurrentProgressMaximumStep, step, progressMessage));
        }

        protected void ResetCurrentProgress()
        {
            CurrentProgressResetted(this, new EventArgs());
        }
    }

    public class AdminJobEventArgs:EventArgs
    {
        public int Maximum;

        public int Step;

        public string ProgressMessage;

        public AdminJobEventArgs(int maximum, int step, string progressMessage)
        {
            this.Maximum = maximum;
            this.Step = step;
            this.ProgressMessage = progressMessage;
        }
    }
}
